<?php

namespace App\Http\Controllers\Admin\Auth;

use App\Models\AdminPasswordReset;
use Illuminate\Http\Request;

use App\Http\Controllers\Admin\BaseController;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends BaseController
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    /**
     * Where to redirect users after resetting success.
     *
     * @var string
     */
    protected $redirectTo = '/admin/dashboard';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest:admin');
    }

    /**
     * Get the guard to be used during authentication. 使用管理员认证
     *
     * @return \Illuminate\Contracts\Auth\StatefulGuard
     */
    protected function guard()
    {
        return Auth::guard('admin');
    }

    public function showResetForm(Request $request, $token = null)
    {
        $passwordReset = AdminPasswordReset::where('token', $token)->first();

        if (!$passwordReset) {
            abort(404);
        }

        return view('auth.passwords.reset')->with([
            'token' => $token,
            'email' => $passwordReset->email
        ]);
    }

    public function redirectToReset(Request $request)
    {
        return redirect("/admin/password/reset/" . $request->hash);
    }
}
